export default {
  namespaced: true, // 命名空间
  state: {
    cartList: []
  },
  mutations: {
    /**
     * goods 商品对象
     */
    addToCart (state, goods) {
      console.log('----goods----', goods)
      const oldGoods = state.cartList.find(item => item.id === goods.id)
      if (oldGoods) {
        oldGoods.num += goods.num
      } else {
        state.cartList.push(goods)
      }
    }
  }
}
